package com.kadron.login;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.security.Identity;

import com.kadron.manager.KMessageManager;
import com.kadron.session.Authenticator;

@AutoCreate
@BypassInterceptors
@Name("loginManager")
@Scope(ScopeType.EVENT)
public class LoginManager extends KMessageManager {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8120895630979302535L;

	public String login() {
		Identity identity = (Identity) Component.getInstance("identity");
		Authenticator authenticator = (Authenticator) Component.getInstance("authenticator");
		try {
			identity.login();
			authenticator.authenticate();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "home";
	}
	
	public String logout() {
		Identity identity = (Identity) Component.getInstance("identity");
		try {
			identity.logout();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "home";
	}
	
}
